/*
 * Temperature.c
 *
 *  Created on: May 23, 2021
 *      Author: Rupert
 */

#include "Temperature.h"

#include "MAX31865.h"

typedef struct _TempData
{
	float Temp;
	float TempLimit;
	uint8_t AlarmFlag;
} TempData;

static TempData temp_data;

void TemperatureInit(void)
{
	temp_data.AlarmFlag = 0;
	temp_data.Temp = 0;
	temp_data.TempLimit = 100;
}

void UpdateTempData()
{
	float sum = 0;
	uint8_t n_samples = 3;
	for (int i = 0; i < n_samples; i++)
	{
		sum += MAX31865_GetTemp();
	}
	temp_data.Temp = sum / n_samples;
}

float getTemperature()
{
	return temp_data.Temp;
}

float getTempLimit()
{
	return temp_data.TempLimit;
}

uint8_t getAlarmFlag()
{
	return temp_data.AlarmFlag;
}

void setAlarmFlag()
{
	temp_data.AlarmFlag = 1;
}

void resetAlarmFlag()
{
	temp_data.AlarmFlag = 0;
}

void setTempLimit(uint8_t newTempLimit)
{
	temp_data.TempLimit = newTempLimit;
}
